//index.js
//获取应用实例
const app = getApp();
var gp = app.globalData;
const net = require("../../utils/net.js");
var utils = require("../../utils/util.js");
Page({
  data: {
    icon: gp.userInfo.avatarUrl,
    gymname: gp.shop_name,
    obj:{
      month_sales_volume: 0,
      today_sales_volume: 0,
      recent_expire: 0,
      count_expire: 0,
      money_expire: 0,
      no_arrival_long_time: 0,
      no_followup_long_time: 0
    }
  },
  onShow(){
    this.onfresh();
  },
  onfresh(){
    var that = this;
    wx.showLoading({
      title: '',
    })
    net.request({
      url: "/StatisticData",
      data: {
        id: gp.id,
        shop_id: gp.shop_id
      },
      success(res) {
        var dt = res.data;
        console.log(dt.data);
        if(dt.flag){
          that.setData({
            obj:dt.data
          })
        }
      }, fail(res) {

      }, complete() {
        wx.hideLoading();
      }
    })
    this.shopname();
  },
  onPullDownRefresh: function () {
    this.onfresh();
    wx.stopPullDownRefresh()
  },
  onLoad: function () {
    
  }, 
  navgo(e){
    console.log(e);
    var route = e.currentTarget.dataset.route;
    utils.Forward("../manager/last/last?type="+route);
  },shopname(){
    var that = this;
    var shopname = wx.getStorageSync("shop_name");
    if (shopname != null && shopname != undefined && shopname.length!=0){
      that.setData({
        gymname: shopname
      })
      return;
    }
    net.request({
      url:"/GetShopInfo",
      data:{
        shop_id:gp.shop_id
      },success(res){
        if(res.data.flag){
          gp.shop_name =shopname =  res.data.data.shop_name;
          wx.setStorageSync("shop_name", res.data.data.shop_name);
          that.setData({
            gymname: shopname
          })
        }else{
          wx.showToast({
            title: res.data.msg,
          })
        }
      },fail(res){

      }
    })

    
  },onReady(){

  }

})
